package com.murfrosoft.airhockey.entities;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

public class UserPaddle extends Paddle {

	@Override
	public void move(int width,int height,float touchX,float touchY) {
		/* Control your paddle */
		oldPositionX = positionX;
		oldPositionY = positionY;
		positionX = touchX;
		positionY = touchY;
		// see what kind of velocity this reports (needed for puck collision later)
		velocityX = positionX - oldPositionX;
	    velocityY= positionY - oldPositionY;
		if( velocityX > 20 ){
			velocityX = 20;
		}
		else if( velocityX < -20 ){
			velocityX = -20;
		}
		if( velocityY > 20 ){
			velocityY = 20;
		}
		else if( velocityY < -20 ){
			velocityY = -20;
		}
		
		if( positionY< height/2 ){		// Keep paddle on your side of table
			positionY = height/2;
		}
		else if( positionY > (height - radius) ){  // Keep paddle from overlapping goal end
			positionY = height - radius;
		}
		
		/* Keep paddle in bounds on x-axis */
		if( positionX < radius ){
			positionX = radius;
		}
		else if( positionX > ( width - radius) ) {
			positionX = width - radius;
		}
		
		
	}

	@Override
	public void draw(Canvas canvas) {
		Paint paddle_color1 = new Paint();
		paddle_color1.setAntiAlias(true);
		paddle_color1.setColor(Color.rgb(255, 100, 100));
		Paint paddle_color2 = new Paint();
		paddle_color2.setAntiAlias(true);
		paddle_color2.setColor(Color.rgb(255, 0, 0));
		/* DRAW TEST PADDLE */
		canvas.drawCircle(positionX, positionY, radius, paddle_color2);
		canvas.drawCircle(positionX, positionY, radius/2, paddle_color1);
		
		
	}

}
